#ifndef _UIDEVICE_H_
#define _UIDEVICE_H_

#include <QMetaType>
#include <QDateTime>
#include <QObject>
#include <QSize>

#define UIDEVICE_SYSTEM_NAME        "Moko Touch"
#define UIDEVICE_SYSTEM_VERSION     "1.0 (0007c)"

class UIAcceleration;
class UIEvent;

typedef enum {
    UIDeviceOrientationUnknown,
    UIDeviceOrientationPortrait,
    UIDeviceOrientationPortraitUpsideDown,
    UIDeviceOrientationLandscapeLeft,
    UIDeviceOrientationLandscapeRight,
    UIDeviceOrientationFaceUp,
    UIDeviceOrientationFaceDown
} UIDeviceOrientation;
Q_DECLARE_METATYPE(UIDeviceOrientation)

#define UIDeviceOrientationIsLandscape(orientation)         \
   ((orientation) == UIDeviceOrientationLandscapeLeft ||    \
    (orientation) == UIDeviceOrientationLandscapeRight)

#define UIDeviceOrientationIsPortrait(orientation)          \
   ((orientation) == UIDeviceOrientationPortrait ||         \
    (orientation) == UIDeviceOrientationPortraitUpsideDown)

#define UIDeviceOrientationIsValidInterfaceOrientation(orientation)  \
   ((orientation) == UIDeviceOrientationPortrait ||                  \
    (orientation) == UIDeviceOrientationPortraitUpsideDown ||        \
    (orientation) == UIDeviceOrientationLandscapeLeft ||             \
    (orientation) == UIDeviceOrientationLandscapeRight)

/* Device Screen Size */
#define kUIDeviceScreenHeight (UIDevice::currentDevice()->screenSize().height())
#define kUIDeviceScreenWidth  (UIDevice::currentDevice()->screenSize().width())
#define kUIDeviceScreenSize   (UIDevice::currentDevice()->screenSize())

typedef enum {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,
    UIDeviceBatteryStateCharging,
    UIDeviceBatteryStateFull,
} UIDeviceBatteryState;
Q_DECLARE_METATYPE(UIDeviceBatteryState)

class UIDevicePrivate;
class UIDevice : public QObject {
    Q_OBJECT

    public:
        static UIDevice *currentDevice (void);

    public:
        QString uniqueIdentifier (void) const;

        // Identifying the Device and Operating System
        QString name (void) const;
        QString model (void) const;
        QString systemName (void) const;
        QString systemVersion (void) const;
        QString serialNumber (void) const;

        QSize screenSize (void) const;

        // Getting the Device Orientation
        bool orientationIsPortrait (void) const;
        bool orientationIsLandscape (void) const;
        UIDeviceOrientation orientation (void) const;

#ifdef UIKIT_SIMULATOR
        void setOrientation (UIDeviceOrientation orientation);
#endif

        void endGeneratingDeviceOrientationNotifications (void);
        void beginGeneratingDeviceOrientationNotifications (void);
        bool generatesDeviceOrientationNotifications (void) const;

        // Getting the Device Battery State
        qreal batteryLevel (void) const;
        QDateTime batteryTimeToFull (void) const;
        QDateTime batteryTimeToEmpty (void) const;
        UIDeviceBatteryState batteryState (void) const;

        // Leds
        bool redLedIsEnabled (void) const;
        void setRedLedEnabled (bool enabled);
        bool blueLedIsEnabled (void) const;
        void setBlueLedEnabled (bool enabled);
        bool orangeLedIsEnabled (void) const;
        void setOrangeLedEnabled (bool enabled);

    Q_SIGNALS:
        void orientationChanged (UIDeviceOrientation orientation);

        void auxButtonPressed (UIEvent *event);
        void powerButtonPressed (UIEvent *event);

    public Q_SLOTS:
        // Vibrate
        void vibrate (qreal force = 0.5f, int time = 1000);
        void stopVibrate (void);

        // System Reboot/Shutdown
        void systemShutdown (void);
        void systemReboot (void);

#ifdef UIKIT_SIMULATOR
        void pressPowerButton (void);
        void pressAuxButton (void);
#endif

    public:
        UIDevice (QObject *parent = 0);
        ~UIDevice();

    private Q_SLOTS:
        void accelerometerNotification (UIAcceleration *acceleration);
        void buttonPressed (int keyCode);

    private:
        UIDevicePrivate *d;
};

#endif /* !_UIDEVICE_H_ */

